home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / misc / vpan100.zip / SU_HYSTB.CPP < prev    next >
C/C++ Source or Header  |  1995-01-19  |  8KB  |  296 lines

  1. //
  2. //  AC SUSCEPTEMETER
  3. //
  4. //   HYSTERESIS
  5. //     BUTTON AND PAINT PROCEDURES (bp and pp)
  6. //
  7. //                       |     Written by O.Rasizade
  8. //                 |       (c) Oct 1992, 1993
  9. //                       |
  10. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. #include <vphead.h>    // must be included first
  12. #pragma hdrstop
  13.  
  14. #include <vpbase.h>
  15. #include <vpinbox.h>
  16. #include <vpindic.h>
  17. #include <vpgraph.h>
  18. #include <vpbutt.h>
  19. #include <vputil.h>
  20.  
  21. #include "suscept.h"
  22. #include "su_bp.h"
  23.  
  24. //-------------------- GLOBAL VARIABLES -------------
  25. extern Indicator<double> *indDisbal,*indModule;
  26. extern TSInbox<int> *ptibAC, *ptibDC;
  27. extern Board *Hysteresis;
  28. extern FILE *dat;
  29. extern char nameHystDat[];    // name of data file
  30. int limDC=512,delDC=1,N=1,hyDelay=500,statusHyst=11;
  31. int _limDC=512;
  32.  
  33.     //---------------------- BACKGROUND PROCEDURE ---------
  34. void far  HystBackgr(void)
  35. {
  36. static int DC;
  37. //---------------------- GRAPH SECTION ---
  38. static int dc0;
  39. static float a10,b10;
  40. char graphtitle[30]="Hysteresis : ";
  41.  
  42. Graph<float,float> *
  43. pgrHyst1 = new Graph<float,float>  (
  44.     x0s,y0s,PERM,graphtitle,
  45.     14,12,    /* number of x & y div.            */
  46.     25,20,    /* number of pixels in every div.    */
  47.  
  48.     -_limDC,-2.5,    /* values of x,y at origin    */
  49.     _limDC/7.,5./12.,/* values of x,y div.        */
  50.                       // Hereafter defaults are used
  51.     procDummy,
  52.     "Constant Field","A1(red) B1(yellow)",    /* text on the axises*/
  53.     "%.1f","%.1f");             /* format of values on divisions*/
  54.  pgrHyst1->OnScreen=1;
  55.  switch (statusHyst)
  56.  {
  57.   case 0:               //--- Init
  58.        if (InitHyst()==-1)
  59.           {DisplayErrorMessage("Cannot create data file");
  60.           statusHyst=10;}
  61.        else
  62.         {
  63.          strcat(graphtitle,nameHystDat);
  64.          pgrHyst1->Paint();
  65.          pgrHyst1->PutDot(0,a1,RED);
  66.          pgrHyst1->PutDot(0,b1,YELLOW);
  67.          dc0=DC=0; a10=a1; b10=b1;
  68.          statusHyst=1;
  69.          }
  70.        break;
  71.   case 1:            //--- Incremential measurement
  72.       delay(hyDelay);
  73.       measureA1B1T();
  74.       sound(1000);
  75.       delay(0);
  76.       nosound();
  77.       fprintf(dat,"\n%d  %.4f   %.4f",constI,a1,b1);
  78.        pgrHyst1->PutLine(dc0,a10,DC,a1,RED);
  79.        pgrHyst1->PutLine(dc0,b10,DC,b1,YELLOW);
  80.        dc0=DC; a10=a1; b10=b1;
  81.       updateIndicators();
  82.       ptibDC->Refresh();
  83.       //    SetTemperature1();
  84.       if ((DC+delDC) <= limDC )
  85.         {DC+=delDC; setConstI(DC);}    // continue this incr loop
  86.       else
  87.                 statusHyst=2;            // start decr loop
  88.       /*  if ((limDC-=delDC) >0 )
  89.            {
  90.         statusHyst=2;            // start decr loop
  91.         indLimDC->Put(limDC);
  92.         }
  93.         else
  94.         statusHyst=10;            // end Hyst measurement
  95.            */
  96.       break;
  97.   case 2:            //--- Decremential measurement
  98.       if ((DC-delDC) < (-limDC))
  99.             statusHyst= 1;  // start inc loop
  100.        /*{
  101.         statusHyst=((limDC-=delDC) > 0)? 1:10;// start inc loop : end Hyst measurement
  102.         indLimDC->Put(limDC);
  103.         }*/
  104.       else        // continue this decr loop
  105.       {
  106.        setConstI(DC-=delDC);
  107.        delay(hyDelay);
  108.        measureA1B1T();
  109.         sound(1000);
  110.         delay(0);
  111.         nosound();
  112.        pgrHyst1->PutLine(dc0,a10,DC,a1,RED);
  113.        pgrHyst1->PutLine(dc0,b10,DC,b1,YELLOW);
  114.        dc0=DC; a10=a1; b10=b1;
  115.        updateIndicators();
  116.        fprintf(dat,"\n%d   %.4f   %.4f",constI,a1,b1);
  117.        ptibDC->Refresh();
  118.        //    SetTemperature1();
  119.        }//else
  120.        break;
  121.   case 10:        //--- Stop Hyst measurement
  122.       fclose(dat);
  123.       measInProgress=0;
  124.       statusHyst=11;    // switch backgr measurement in idle mode
  125.       if ( !Confirm(" Save data file ? ", YES) )
  126.         unlink(nameHystDat);
  127.       pgrHyst1->Remove();
  128.       break;
  129.   case 11:;        //--- Dummy entry. Measurement is idle.
  130.  }
  131. delete pgrHyst1;
  132. }
  133.  
  134. //-----------------  HYSTERESIS BOARD  ------
  135.  
  136.         //------ HYSTERESIS BOARD BUTTON PROCs ----
  137.  
  138. //------------------------------------ AC1 -----
  139. int far  tibpAC1(int AC)
  140. {
  141.  setAltI(AC);
  142.  return AC;
  143. }
  144.  
  145. //------------------------------------ START -----
  146. void far  bpStart(void)
  147. {
  148. if (!measInProgress)
  149.  {
  150.   statusHyst=0;    // start backgr measurement
  151.   _limDC=limDC;
  152.  }
  153. }
  154.  
  155. //------------------------------------ STOP -----
  156. void far  bpStop(void)
  157. {
  158. if (measInProgress)
  159.  {statusHyst=10;}    // switch backgr measurement in stop mode
  160. }
  161.  
  162. //------------------------------ HYST BUTTON PROCEDURE ------
  163. void far  bpHyst(void)
  164. {
  165. int X0=Hysteresis->x0, Y0=Hysteresis->y0p+5;
  166.  
  167. statusHyst=11;        // No measurement - idle backgr. proc
  168.  
  169. butsystem *
  170.  pbsHyst = new butsystem ;
  171.  
  172.  TSInbox<int> *ptibAC1= new TSInbox<int>
  173.     ( X0, Y0, "AC:",
  174.       5, &altI,"%d","%d", tibpAC1,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  175.  
  176.  TSInbox<int> *ptibDelay= new TSInbox<int>
  177.     ( ptibAC1->xmax, Y0, "Delay:",
  178.       5, &hyDelay,"%d","%d",NULL,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  179.  
  180.  TSInbox<int> *ptibLimDC= new TSInbox<int>
  181.     ( ptibDelay->xmax, Y0, "DC limit:",
  182.       5, &limDC,"%d","%d",NULL,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  183.  
  184.  TSInbox<int> *ptibDelDC= new TSInbox<int>
  185.     ( ptibLimDC->xmax, Y0, "Delta:",
  186.       5, &delDC,"%d","%d",NULL,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  187.  
  188.  TSInbox<int> *ptibN= new TSInbox<int>
  189.     ( ptibDelDC->xmax, Y0, "N:",
  190.       5, &N,"%d","%d",NULL, SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  191.  
  192.  
  193. int axmax=ptibN->xmax;
  194.     //---------------- Buttons ------
  195. #define chBUTSHF     10
  196.  
  197. butgrp gr2(X0+chBUTSHF,ptibN->ymax+6,(ptibN->xmax-ptibAC1->x0-2*chBUTSHF)>>1,20);
  198.   button butStop("stoP measurement",'P','p',bpStop,SMALL_FONT,4);
  199.   button butStart("Start measurement",'S','s',bpStart,SMALL_FONT,4);
  200.  
  201. Hysteresis->ChangeSize(axmax-X0,butStart.ymax-Hysteresis->y0+chBUTSHF);// size of board
  202.  
  203.     //---------------- Paint whole board
  204. Hysteresis->Paint();
  205.  
  206. ptibAC1->Paint();
  207. ptibDelay->Paint();
  208. ptibLimDC->Paint();
  209. ptibDelDC->Paint();
  210. ptibN->Paint();
  211.  
  212. ptibAC1->Refresh();
  213. ptibDelay->Refresh();
  214. ptibLimDC->Refresh();
  215. ptibDelDC->Refresh();
  216. ptibN->Refresh();
  217.  
  218. gr2.Paint();
  219.  
  220. pbsHyst->NextButton();
  221. do
  222.   pbsHyst->Loop(HystBackgr);
  223. while(measInProgress);
  224. delete pbsHyst;
  225.  
  226.  ptibAC->Refresh();
  227.  
  228. Hysteresis->Remove();
  229. Hysteresis->MkActive();
  230. object::RepaintScr();
  231.  
  232. delete ptibAC1;
  233. delete ptibDelay;
  234. delete ptibLimDC;
  235. delete ptibDelDC;
  236. delete ptibN;
  237.  
  238. }//----- bpHyst(void)
  239.  
  240. //+++++++++++++++++++++++++++++++++++++++++++++++++++++
  241. //------------------------------ HYSTERESIS GRAPH -----
  242.  
  243. int  find_ch(char c)
  244. {
  245. int ch;
  246.  while ( ( (ch=getc(dat)) != c ) && (ch!=EOF) );
  247.  return ch;
  248. }
  249.  
  250. //------------------------
  251. void far  bpHystGraph(void)
  252. {
  253. int dc0,dc1;
  254. float a10,a11,b10,b11;
  255. int blank;
  256.  
  257.  if ( (dat = fopen(nameHystDat,"rt")) == NULL )
  258.    DisplayErrorMessage("No measurement has been made yet");
  259.  else
  260.  {
  261.   find_ch('=');
  262.   fscanf(dat,"%d",&blank);
  263.   find_ch('=');
  264.   fscanf(dat,"%d",&limDC);
  265.   find_ch('@');
  266.  char graphtitle[30]="Hysteresis : ";
  267.  Graph<float,float>  grHyst(
  268.     x0s,y0s,POPUP,strcat(graphtitle,nameHystDat),
  269.     14,12,    /* number of x & y div.            */
  270.     25,20,    /* number of pixels in every div.    */
  271.  
  272.     -limDC,-2.5,    /* values of x,y at origin    */
  273.     limDC/7.,5./12.,/* values of x,y div.        */
  274.                       // Hereafter defaults are used
  275.     procNULL,
  276.     "Constant Field","A1(red) B1(yellow)",    /* text on the axises*/
  277.     "%.1f","%.1f");             /* format of values on divisions*/
  278.  
  279.   grHyst.Paint();
  280.   fscanf(dat,"%d%f%f",&dc0,&a10,&b10);
  281.   grHyst.PutDot(dc0,a10,RED);
  282.   grHyst.PutDot(dc0,b10,YELLOW);
  283.   while ( fscanf(dat,"%d%f%f",&dc1,&a11,&b11)!=EOF )
  284.   {
  285.    grHyst.PutLine(dc0,a10,dc1,a11,RED);
  286.    grHyst.PutLine(dc0,b10,dc1,b11,YELLOW);
  287.    a10=a11;
  288.    b10=b11;
  289.    dc0=dc1;
  290.    }
  291.   fclose(dat);
  292.   getch();
  293.   grHyst.Remove();
  294.   }//-- else
  295. }//--------------- END of bpHystGraph(void) ---------
  296.